﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace _82_实现IEnumerator接口_集合
{
    class Program
    {
        static void Main(string[] args)
        {
            MyEnumerator 实例化 = new MyEnumerator();
            Console.WriteLine("10个随机整数如下：");
            while (实例化.MoveNext())
            {
                Console.WriteLine(实例化.Current);
            }
            Console.Read();

        }
    }
    public class MyEnumerator : IEnumerator<int>
    {
        Random rand = null;
        int count;

        public MyEnumerator()
        {
            rand = new Random();
            count = 0;
            Current = default(int);
        }

        public int Current { get; private set; }

        object IEnumerator.Current
        {
            get { return Current; }
        }

        public void Dispose()
        {
            rand = null;
        }

        public bool MoveNext()
        {
            if (++count > 10)
                return false;
            Current = rand.Next();
            return true;
        }

        public void Reset()
        {
            count = 0;
            Current = default(int);
        }

    }
}
